package anthology.daily_question._24_12;
//https://leetcode.cn/problems/semi-ordered-permutation/description/?envType=daily-question&envId=2024-12-11
public class _2717半有序排列 {
    class Solution {
        public int semiOrderedPermutation(int[] nums) {
            int n = nums.length;
            int first=0,last=0;
            for(int i=0; i<n; i++){
                if(nums[i] == 1){
                    first = i;
                }if(nums[i] == n){
                    last = i;
                }
            }
            return first + n - 1 - last - (last < first ? 1 : 0);
        }
    }
}
